package com.isunland.managesystem.ui;

import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import com.isunland.managesystem.R;
import com.isunland.managesystem.common.AppManager;
import com.isunland.managesystem.utils.ToastUtil;

/**
 * Created by wu on 2016/5/23.
 */
public class LoginActivity extends SingleFragmentActivity {

  private long mExitTime;

  @Override protected Fragment createFragment() {
    return new LoginFragment();
  }

  @Override public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
      case KeyEvent.KEYCODE_BACK:
        // 判断是不是超过2秒又点击返回键，超过就toast一遍，小于2秒就退出

        if ((System.currentTimeMillis() - mExitTime) > 2000) {
          ToastUtil.show(R.string.sure_to_exit);
          mExitTime = System.currentTimeMillis();
        } else {
          AppManager.getAppManager().finishAllActivity();
        }
        return true;
      default:
        break;
    }

    return super.onKeyDown(keyCode, event);
  }

  protected void onCreate(android.os.Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    //        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    //                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    Toolbar toolbar = getToolBar();
    View layout = findViewById(R.id.appbar);
    if (layout != null) layout.setVisibility(View.GONE);
  }
}
